// Column chart
function type_0_chart(from_mask)
{
    var options= {
        chart: {
            type: 'columnrange',
            inverted: true,
             backgroundColor:'transparent'
        },
        title: {
            text: 'Malicious Web Active Time'
        },
        xAxis: {
            categories:[]
        },
        yAxis: {
            allowDecimals: false,
            min: 0,
            title: {
                text: 'Active Time From 2013-09-30'
            }
        },
        tooltip: {
            valueSuffix: 'day'
            
        },
        plotOptions: {
            columnrange: {
                dataLabels: {
                    enabled: true,
                    formatter: function () {
                        //this.points[i].y
                        return this.y + 'day';
                    }
                }
            }
        },
        series:[{
            name:"ActiveTime",
            data:[]
        }]
    };

 $.getJSON("chart_phish.php?type=0&from_mask="+from_mask,function(jdata) {

    //var t = JSON.stringify( options_0 );
    //var options = JSON.parse( t );
    var categories=[];
    var mpoint=[];
    $.each(jdata, function(key, data){ 
        categories.push(key); 
        var t=[data[0],data[1]];
        mpoint.push(t);
    })
    


    options.chart.renderTo = 'container1';
    options.series[0].data=mpoint;
    options.xAxis.categories=categories;
    var chart1 = new Highcharts.Chart(options);


    

})

}

function type_1_chart(from_mask)
{
    var options_0 = {
        chart: {
            type: 'column',
             backgroundColor:'transparent'
        },
        title: {
            text: 'Port Scan Result'
        },
        xAxis: {
            categories:[]
        },
        yAxis: {
            allowDecimals: false,
            min: 0,
            title: {
                text: 'Number of IPs'
            }
        },
        tooltip: {
            formatter: function() {

                return '<b>'+ this.x +'</b><br/>'+
                    this.series.name +': '+ this.y +'<br/>'+
                    'Total: '+ this.point.stackTotal+'<br/>'+
                    'Percentage: '+(this.point.y/this.point.stackTotal).toFixed(4)*100+'%';
            }
        },
        plotOptions: {
            column: {
                stacking: 'normal'
            }
        },
        series:[{},{}]
};

 $.getJSON("chart_phish.php?type=1&from_mask="+from_mask,function(jdata) {

    var tmp_total=[];
    var tmp_region=[];
    //var tmp_total_com=[];
    //var tmp_region_com=[];
    var reg_key={};
    $.each(jdata, function(key, data) {
        var tuple=data;
        var port=tuple[0];
        var region=tuple[1];
        var count=tuple[2];
        if(tmp_total[port]==null)
        {
            tmp_total[port]=0;
            //tmp_total_com[port]=0;
        }
        if(tmp_region[port]==null)
        {
            tmp_region[port]=[];
            var t=[region,count];
            tmp_region[port].push(t);

        }
        else{
            var t=[region,count];
            tmp_region[port].push(t);
        }
        reg_key[region]=0;
        //alert(region+''+reg_key);
        tmp_total[port]=tmp_total[port]+parseInt(count);
    })
    //alert(reg_key);

    var categories=[];

    var data=[]
    for(var i in tmp_total){
        //alert(d2[i][0]);
    
        categories.push(i);
        var t=[i,tmp_total[i]];
        data.push(t);
    }
    //var options=options_0;
    var t = JSON.stringify( options_0 );
    var options = JSON.parse( t );
    options.chart.renderTo = 'container1';
    options.chart.type = 'pie';
    options.title.text="Port Scan Result";
    options.tooltip={
                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            };
    options.series=[{}];
    options.series[0].name="open port";
    options.series[0].data=data;
    options.xAxis.categories=categories;
    var chart1 = new Highcharts.Chart(options);
   

    var t = JSON.stringify( options_0 );
    var options = JSON.parse( t );
    var categories=[]
    options.series=[];
    var c=0;
    for(var i in reg_key){
        categories.push(i);
    }

    for(var i in tmp_region){
        //alert(d2[i][0]);
        options.series.push([]);
        options.series[c].name=i;
        options.series[c].data=tmp_region[i];
        c=c+1;
    }
    options.tooltip={
                formatter: function() {
                return '<b>'+ this.x +'</b><br/>'+
                    this.series.name +': '+ this.y +'<br/>'+
                    'Total: '+ this.point.stackTotal+'<br/>'+
                    'Percentage: '+(this.point.y/this.point.stackTotal).toFixed(4)*100+'%';
            }
            };
    options.chart.type = 'column';
options.title.text="Port Scan Result by Region";
    options.plotOptions.bar={
                stacking: 'normal'
            };
    options.chart.renderTo = 'container3';
    options.xAxis.categories=categories;
    var chart2 = new Highcharts.Chart(options);


    
})

}
function simpleSearch()
{
 
type_0_chart();
}
type_0_chart();
